package com.yoso.shop.interfaces.controller.commodity;

import com.alibaba.fastjson.JSON;
import com.yoso.shop.application.service.ICommodityBranchService;
import com.yoso.shop.domain.commodity.CommodityBranchEntity;
import com.yoso.shop.domain.commodity.CommodityBranchEntityExample;
import com.yoso.shop.infrastructure.base.controller.BaseController;
import com.yoso.shop.infrastructure.base.controller.BaseResponse;
import com.yoso.shop.infrastructure.base.service.BaseEntityExample;
import com.yoso.shop.infrastructure.base.service.IBaseService;
import com.yoso.shop.infrastructure.cache.CommodityCacheServer;
import com.yoso.shop.infrastructure.constants.commodity.MasterEnum;
import com.yoso.shop.interfaces.vo.commodity.CommodityBranchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author yoso
 * @date 2021/12/8
 */
@RestController
@RequestMapping("/commodityClassify")
@Slf4j
@Api("商品分类")
public class CommodityClassifyController extends BaseController<CommodityBranchVo, CommodityBranchEntity> {
    @Autowired
    private ICommodityBranchService commodityBranchService;
    @Autowired
    private CommodityCacheServer commodityCacheServer;
    @Override
    public CommodityBranchEntity V2E(CommodityBranchVo data) {
        return JSON.parseObject(JSON.toJSONString(data),CommodityBranchEntity.class);
    }

    @Override
    public CommodityBranchVo E2V(CommodityBranchEntity data) {
        return JSON.parseObject(JSON.toJSONString(data),CommodityBranchVo.class);

    }

    @Override
    public IBaseService<CommodityBranchEntity, CommodityBranchEntityExample> getService() {
        return this.commodityBranchService;
    }
    @ApiOperation("获得商品主分支")
    @GetMapping("getMasterBranch")
    public BaseResponse<Map<String, String>> getMasterBranch() {
        Map<String, List<CommodityBranchEntity>> commodityBranchCacheMap = commodityCacheServer.getCommodityBranchCacheMap();
        List<CommodityBranchEntity> list = commodityBranchCacheMap.get("101");
        list.forEach(System.out::println);
        return this.success("操作成功", MasterEnum.getSortMap());
    }
    @ApiOperation("获得商品再分支")
    @GetMapping("getBranch")
    public BaseResponse<Map<String, String>> getBranch() {
        return this.success("操作成功", MasterEnum.getSortMap());
    }
}
